import javax.sql.DataSource;
import com.mysql.cj.jdbc.MysqlDataSource;
//封装datasourse，使他成为单例
class DBUtil{
    private static volatile DataSource dataSource = null;
    private static Object locker = new Object();

    public static DataSource getDataSource(){
        if(dataSource == null){
            synchronized (locker){
                if(dataSource == null){
                    MysqlDataSource mysqlDataSource = new MysqlDataSource();
                    ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/java_test?characterEncoding=utf8&useSSL=false");
                    ((MysqlDataSource)dataSource).setUser("root");
                    ((MysqlDataSource)dataSource).setPassword("kenny20060304");
                    dataSource = mysqlDataSource;
                }
            }
        }
        return dataSource;
    }
}



public class Demo3 {
}
